package com.uniquesoft.common;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Map;
import java.util.Scanner;

import com.uniquesoft.excelreader.FolderHandler;
import com.uniquesoft.excelreader.ReadExcelUtils;
import com.uniquesoft.excelreader.ZipHandler;

public class SourceFileLoader {
    
    public static void main(String[] args) {

 //       @SuppressWarnings("resource")
//		Scanner scanner = new Scanner( System.in );
        System.out.print( "请输入待解析文件（.xsl/.xslx/.zip）或文件夹路径: " );
//        String path = scanner.nextLine();
        //just for test 
        String path = "/sandbox/Workspace/excelhandler/src/excel1.xls";
        
    	loadExcelFile(path); // /sandbox/A_Test/testExcel/王铮干部任免审批表 (version 1).xls
    	
//    	loadFolder(path); // /sandbox/A_Test/testExcel
    	
//    	loadZipFile(path); // /sandbox/A_Test/testExcel/testZip.zip
    }
    
    public static Map<Integer, Map<Integer, Object>> loadExcelFile(String filepath){
        try {
            ReadExcelUtils excelReader = new ReadExcelUtils(filepath);

            Map<Integer, Map<Integer, Object>> map = excelReader.readExcelContent();
            System.out.println("***************获得 "+filepath+" 的内容***************");
            
            for (Map.Entry<Integer, Map<Integer, Object>> entry : map.entrySet()) {  
                System.out.println( entry.getKey() + " = " + entry.getValue());  
            } 
            
            return map;
            
        } catch (FileNotFoundException e) {
            System.out.println("未找到指定路径的文件!");
            e.printStackTrace();
            return null;
        }catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
    
    public static ArrayList<Map<Integer, Map<Integer, Object>>> loadFolder(String path){
        try {
            FolderHandler folderHandler = new FolderHandler(path);
            // 对读取Excel表格内容测试
            ArrayList<Map<Integer, Map<Integer, Object>>> mapList = folderHandler.resolveExcelFiles();
            return mapList;
        } catch (FileNotFoundException e) {
            System.out.println("未找到指定路径的文件!");
            e.printStackTrace();
            return null;
        }catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
    
    public static ArrayList<Map<Integer, Map<Integer, Object>>> loadZipFile(String path){
        try {
            ZipHandler zipHandler = new ZipHandler(path);
            // 对读取Excel表格内容测试
            ArrayList<Map<Integer, Map<Integer, Object>>> mapList = zipHandler.resolveZipFile();
            return mapList;
        } catch (FileNotFoundException e) {
            System.out.println("未找到指定路径的文件!");
            e.printStackTrace();
            return null;
        }catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    	
    }
}
